package com.hoas.quickstart.threads.chapter03.chapter03_1_4_01;

public class Service {

    public void testMethod(Object lock){
        try {
            synchronized (lock) {
                System.out.println("begin wait() thread-name=" + Thread.currentThread().getName() + " time=" + System.currentTimeMillis());
                lock.wait();
//                Thread.sleep(40000);
                System.out.println("end wait() thread-name=" + Thread.currentThread().getName() + " time=" + System.currentTimeMillis());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public void synNotifyMethod(Object lock) {
        try {
            synchronized (lock) {
                System.out.println("begin notify() thread-name=" + Thread.currentThread().getName() + " time=" + System.currentTimeMillis());
                lock.notify();
                Thread.sleep(5000);
                System.out.println("end notify() thread-name=" + Thread.currentThread().getName() + " time=" + System.currentTimeMillis());
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

}
